home *** CD-ROM | disk | FTP | other *** search
/ Champak 49 / Volume 49 - JOGO DISK .iso / Games / hungerstrike.swf / scripts / __Packages / npb / NPBTracker.as
Encoding:
Text File  |  2007-09-28  |  6.1 KB  |  218 lines

  1. class npb.NPBTracker extends MovieClip
  2. {
  3.    var trackerVersion;
  4.    var trackerVersiontxt;
  5.    var eventCount;
  6.    var npbso;
  7.    var autohide;
  8.    var productID;
  9.    var clientID;
  10.    var passkey;
  11.    var instance;
  12.    var status;
  13.    var display;
  14.    var machineID;
  15.    var domain = this._url;
  16.    var SCRIPT_PROTOCOL = "http://";
  17.    var SCRIPT_DOMAIN = "www.npbmedia.com";
  18.    var TEST_SCRIPT_DOMAIN = "devserver2";
  19.    var SCRIPT_URL = npb.NPBTracker.prototype.SCRIPT_PROTOCOL + npb.NPBTracker.prototype.SCRIPT_DOMAIN + "/tracker/tracker_recorder.php";
  20.    var TEST_SCRIPT_URL = npb.NPBTracker.prototype.SCRIPT_PROTOCOL + npb.NPBTracker.prototype.TEST_SCRIPT_DOMAIN + "/tracker_1_1/tracker_recorder.php";
  21.    var isDev = false;
  22.    var isDebug = true;
  23.    var isValid = true;
  24.    var isValidConnection = true;
  25.    function NPBTracker()
  26.    {
  27.       super();
  28.       this.trackerVersion = "1.2";
  29.       this.trackerVersiontxt.text = this.trackerVersion;
  30.       this.setStatus("NPB Tracker",true);
  31.       this.eventCount = 0;
  32.       AsBroadcaster.initialize(this);
  33.       this.npbso = this.getSharedObject();
  34.       System.security.allowDomain(this.SCRIPT_DOMAIN);
  35.       _global.npbTracker = this;
  36.    }
  37.    function onLoad()
  38.    {
  39.       if(!this.init())
  40.       {
  41.          this.watch("productID",this.init);
  42.          this.watch("clientID",this.init);
  43.          this.watch("passkey",this.init);
  44.       }
  45.       else
  46.       {
  47.          if(this.autohide)
  48.          {
  49.             this._visible = false;
  50.          }
  51.          this.recordEvent("load");
  52.       }
  53.    }
  54.    function getSharedObject()
  55.    {
  56.       return SharedObject.getLocal("NPBTracker" + this.productID,"/");
  57.    }
  58.    function init()
  59.    {
  60.       if(this.productID < 0)
  61.       {
  62.          this.setStatus("Error: Product ID not specified",true);
  63.          return false;
  64.       }
  65.       if(this.clientID == -1)
  66.       {
  67.          this.setStatus("Error: ClientID not specified",true);
  68.          return false;
  69.       }
  70.       if(this.passkey == "")
  71.       {
  72.          this.setStatus("Error: Passkey not specified",true);
  73.          return false;
  74.       }
  75.       this.setStatus("Initialised",true);
  76.       return true;
  77.    }
  78.    function onRelease()
  79.    {
  80.       if(this.isDebug)
  81.       {
  82.          this.recordEvent("Test Event");
  83.       }
  84.    }
  85.    function recordEvent(eventName)
  86.    {
  87.       if(this.isDisabled())
  88.       {
  89.          this.setStatus("Error: This Tracker has been remotely disabled");
  90.          return undefined;
  91.       }
  92.       if(!this.isValid)
  93.       {
  94.          this.setStatus("Error: Invalid clientid / password combination");
  95.          return undefined;
  96.       }
  97.       if(!this.isValidConnection)
  98.       {
  99.          this.setStatus("Error: Connection unavailable");
  100.          return undefined;
  101.       }
  102.       var me = this;
  103.       var sendEvent = this.createEmptyMovieClip("sendEvent" + this.eventCount,this.eventCount);
  104.       var e = sendEvent.createEmptyMovieClip("e",0);
  105.       this.eventCount++;
  106.       e.eventName = eventName;
  107.       e.instance = this.instance;
  108.       e.productID = this.productID;
  109.       e.domain = this.domain;
  110.       e.clientID = this.clientID;
  111.       e.trackerversion = this.trackerVersion;
  112.       e.passkey = this.passkey;
  113.       e.machineid = this.getMachineID();
  114.       sendEvent.onData = function()
  115.       {
  116.          var interval;
  117.          var timeout = 0;
  118.          trace("sendEvent.onData");
  119.          interval = setInterval(function()
  120.          {
  121.             if(timeout++ < 100)
  122.             {
  123.                if(e.eventid || timeout++ > 100)
  124.                {
  125.                   clearInterval(interval);
  126.                   trace("SendEvent::onData");
  127.                   me.setStatus("recieve:\'" + eventName + "\':" + e.eventid);
  128.                   me.setStatus("recieve:\'isvalid\':" + e.isvalid);
  129.                   me.setStatus("recieve:\'machineid\':" + e.machineid);
  130.                   if(me.machineID != Number(e.machineid))
  131.                   {
  132.                      me.setMachineID(e.machineid);
  133.                   }
  134.                   if(e.disableDate != undefined)
  135.                   {
  136.                      var dd = e.disableDate.split("|");
  137.                      var checkBack = new Date(dd[0],dd[1] - 1,dd[2],12,0,0);
  138.                      me.disable(checkBack);
  139.                   }
  140.                   me.isValid = e.isvalid;
  141.                   me.broadcastMessage("onData",sendEvent);
  142.                }
  143.             }
  144.             else
  145.             {
  146.                this.isValidConnection = false;
  147.             }
  148.          }
  149.          ,100);
  150.       };
  151.       if(this.isDev)
  152.       {
  153.          this.SCRIPT_URL = this.TEST_SCRIPT_URL;
  154.       }
  155.       trace("NPBTracker::recordEvent" + this.SCRIPT_URL);
  156.       e.loadMovie(this.SCRIPT_URL,"POST");
  157.       this.setStatus("send:\'" + eventName + "\':" + this.eventCount);
  158.    }
  159.    function setStatus(str, reset)
  160.    {
  161.       if(reset)
  162.       {
  163.          this.status = str + "\n";
  164.       }
  165.       else
  166.       {
  167.          this.status += str + "\n";
  168.       }
  169.       this.display.scroll = this.display.maxscroll;
  170.    }
  171.    function getMachineID()
  172.    {
  173.       this.machineID = this.npbso.data.machineID;
  174.       if(this.machineID == "")
  175.       {
  176.          trace("no machine id set");
  177.          this.machineID = -1;
  178.       }
  179.       return Number(this.machineID);
  180.    }
  181.    function setMachineID(id)
  182.    {
  183.       this.npbso.data.machineID = id;
  184.       this.npbso.flush();
  185.    }
  186.    function isDisabled()
  187.    {
  188.       trace("Checking Enable");
  189.       if(this.npbso.data.disabled != undefined)
  190.       {
  191.          var now = new Date();
  192.          if(now.getTime() < this.npbso.data.disabled.getTime())
  193.          {
  194.             trace(this.npbso.data.disabled);
  195.             return true;
  196.          }
  197.          trace("time elaspsed: " + this.npbso.data.disabled);
  198.          this.enable();
  199.       }
  200.       return false;
  201.    }
  202.    function disable(d)
  203.    {
  204.       this.npbso.data.disabled = d;
  205.       this.npbso.flush();
  206.       trace("disabled");
  207.    }
  208.    function enable()
  209.    {
  210.       this.npbso.data.disabled = null;
  211.       delete this.npbso.data.disabled;
  212.       this.npbso.flush();
  213.       delete this.npbso;
  214.       this.npbso = this.getSharedObject();
  215.       trace("enabled");
  216.    }
  217. }
  218.